package edu.gyc.objecthomework; /**

 File name: PersonImproved.java

 Class for a PersonImproved.

 An object of this class has two attributes, a name and an age.
 Public methods:
	Set just the name, just the age, or both.
	Test if two persons are equal (same name and age).
	Test if two persons have the same name.
	Test if two persons have the same age.
	Test if one person is older than another.
	Test if one person is younger than another.

 Preconditions:
	For set methods: the person has been created.
	For test methods: the persons have been created and have
		values for name and age.

 Postconditions:
	Set methods: one or both attributes is assigned a value.
	Test methods: true or false is returned.

 Based on: Self-Test Question #16 in Chapter 5.

 Modified by: Lew Rakocy
 email address: Lrakocy@devrycols.edu
 Date: 8/20/2000
 Last changed:
 Updated for fourth edition by Brian Durney, November 2004.

*/
import java.util.*;

public class PersonImproved
{
    private String name;
    private int age;

    public void readInput()
    {
        Scanner keyboard = new Scanner(System.in);

        System.out.println("What is the person's name?");
        name = keyboard.nextLine();

        System.out.println("What is the person's age?");
        age = keyboard.nextInt();
        while (age < 0)
        {
            System.out.println("Age cannot be negative.");
            System.out.println("Reenter age:");
            age = keyboard.nextInt();
        }
    }

    public void writeOutput()
    {
        System.out.println("Name = " + name);
        System.out.println("Age = " + age);
    }

    public void set(String newName, int newAge)
    {
        name = newName;
        if (newAge >= 0)
            age = newAge;
        else
        {
            System.out.println("ERROR: Used a negative age.");
            System.exit(0);
        }
    }

    public void setName(String newName)
    {
        name = newName;
    }

    public void setAge(int newAge)
    {
        if (newAge >= 0)
            age = newAge;
        else
        {
            System.out.println("ERROR: Used a negative age.");
            System.exit(0);
        }
    }

    public String getName()
    {
        return name;
    }

    public int getAge()
    {
        return age;
    }

    public boolean equals(PersonImproved another)
    {
        return(this.name.equalsIgnoreCase(another.name)
               && this.getAge() == another.getAge());
    }

    public boolean isSameName(PersonImproved another)
    {
        return(this.name.equalsIgnoreCase(another.name));
    }

    public boolean isSameAge(PersonImproved another)
    {
        return(this.getAge() == another.getAge());
    }

    public boolean isOlderThan(PersonImproved another)
    {
        return(this.getAge() > another.getAge());
    }

    public boolean isYoungerThan(PersonImproved another)
    {
        return(this.getAge() < another.getAge());
    }
}
